import { PlusOutlined } from '@ant-design/icons';
import { ModalForm } from '@ant-design/pro-form';
import { Button, message } from 'antd';
import React from 'react';

import { IMenu } from '@/models/user';
import { addMenus } from '@/services/system/menu';

import MenuForm from './components/MenuForm';
import type { menuProps } from './type';

const AddMenu: React.FC<menuProps> = ({ onReload }) => {
  return (
    <ModalForm<IMenu>
      title="新建菜单"
      trigger={
        <Button type="primary">
          <PlusOutlined />
          新建菜单
        </Button>
      }
      modalProps={{
        keyboard: false,
        maskClosable: false,
        onCancel: () => console.log('run'),
      }}
      onFinish={async (values) => {
        await addMenus(values);
        message.success('提交成功');
        onReload && onReload();
        return true;
      }}>
      <MenuForm />
    </ModalForm>
  );
};

export default AddMenu;
